package com.tr.rentcar.controller.userc;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.tr.rentcar.common.StringUtils;
import com.tr.rentcar.model.bean.User;
import com.tr.rentcar.model.bean.UserRecord;
import com.tr.rentcar.model.dao.UserDao;

/**
 * Servlet implementation class UserDocument
 */
@WebServlet("/user/document")
public class UserDocumentsController extends HttpServlet {
		UserDao ud=new UserDao();
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {
			User user=(User) request.getSession().getAttribute("userinfo");
			User users = ud.findByid(user.getUid());
			request.setAttribute("users", users);
			request.getRequestDispatcher("/WEB-INF/jsp/user_document.jsp").forward(request, response);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		String userName = request.getParameter("userName");
		String utel = request.getParameter("utel");
		String uemail = request.getParameter("uemail");
		User user=(User) request.getSession().getAttribute("userinfo");
		PrintWriter out=response.getWriter();
		try {
			user.setUemail(uemail);
			user.setUtel(utel);
			user.setUname(userName);
			request.getSession().setAttribute("userinfo", user);
			out.println(ud.xginfo(uemail,utel,userName,user.getUid()));
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
	}

}
